package view;

import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import controller.EventController;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

public class EventPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String[] HOUR = { "00", "01", "02", "03", "04", "05",
			"06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
			"17", "18", "19", "20", "21", "22", "23" };
	private static final String[] MINUTE = { "00", "01", "02", "03", "04",
			"05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
			"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
			"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
			"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
			"49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", };
	EventTableModel eventTableModel = new EventTableModel();
	JTable eventTable = new JTable(eventTableModel);
	JLabel eventLabel = new JLabel("Event:");
	JLabel eventNameLabel = new JLabel("EventName:");
	JLabel timeLabel = new JLabel("Time:");
	JLabel recyleLabel = new JLabel("Recyle:");
	JLabel introductionLabel = new JLabel("Introduction:");
	JLabel hourLabel = new JLabel("HH");
	JLabel minuteLabel = new JLabel("MM");
	JTextField eventNameField = new JTextField();
	JComboBox hourComboBox = new JComboBox(HOUR);
	JComboBox minuteComboBox = new JComboBox(MINUTE);
	JTextField fileField = new JTextField();
	JTextArea introductionArea = new JTextArea(10, 10);
	JCheckBox monCheckBox = new JCheckBox("Monday");
	JCheckBox tueCheckBox = new JCheckBox("Tuesday");
	JCheckBox wedCheckBox = new JCheckBox("Wednesday");
	JCheckBox thuCheckBox = new JCheckBox("Thuesday");
	JCheckBox friCheckBox = new JCheckBox("Friday");
	JCheckBox satCheckBox = new JCheckBox("Saturday");
	JCheckBox sunCheckBox = new JCheckBox("Sunday");
	JCheckBox soundCheckBox = new JCheckBox("Sound Alert!", true);
	JCheckBox windowCheckBox = new JCheckBox("Window Alert!", true);
	JButton browseButton = new JButton("Browse");
	JButton modifyButton = new JButton("Modify");
	JButton addButton = new JButton("Add");
	JButton removeButton = new JButton("Remove");

	EventController eventController;
	TaskFrame taskFrame;

	public EventPanel(TaskFrame frame) {

		this.taskFrame = frame;
		eventController = new EventController(this);

		GridBagLayout gbl = new GridBagLayout();
		setLayout(gbl);
		GridBagConstraints constraints = new GridBagConstraints();

		// eventLabel
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.anchor = GridBagConstraints.WEST;
		gbl.setConstraints(eventLabel, constraints);
		this.add(eventLabel);
		// eventNameLabel
		constraints.gridx = 1;
		constraints.anchor = GridBagConstraints.EAST;
		gbl.setConstraints(eventNameLabel, constraints);
		this.add(eventNameLabel);
		// timeLabel
		constraints.gridy = 1;
		gbl.setConstraints(timeLabel, constraints);
		this.add(timeLabel);
		// recyleLabel
		constraints.gridy = 2;
		gbl.setConstraints(recyleLabel, constraints);
		this.add(recyleLabel);
		// introductionLabel
		constraints.gridy = 6;
		gbl.setConstraints(introductionLabel, constraints);
		this.add(introductionLabel);
		constraints.anchor = GridBagConstraints.CENTER;

		// eventNameField
		constraints.gridx = 2;
		constraints.gridy = 0;
		constraints.gridwidth = 6;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		gbl.setConstraints(eventNameField, constraints);
		this.add(eventNameField);
		// hourComboBox
		constraints.gridx = 2;
		constraints.gridy = 1;
		constraints.gridwidth = 2;
		gbl.setConstraints(hourComboBox, constraints);
		this.add(hourComboBox);
		// hourLabel
		constraints.gridx = 4;
		constraints.gridy = 1;
		constraints.gridwidth = 1;
		gbl.setConstraints(hourLabel, constraints);
		this.add(hourLabel);
		// minuteComboBox
		constraints.gridx = 5;
		constraints.gridy = 1;
		constraints.gridwidth = 2;
		gbl.setConstraints(minuteComboBox, constraints);
		this.add(minuteComboBox);
		// minuteLabel
		constraints.gridx = 7;
		constraints.gridy = 1;
		constraints.gridwidth = 1;
		gbl.setConstraints(minuteLabel, constraints);
		this.add(minuteLabel);
		// fileField
		constraints.gridx = 3;
		constraints.gridy = 4;
		constraints.gridwidth = 4;
		gbl.setConstraints(fileField, constraints);
		this.add(fileField);
		// introductionArea
		constraints.gridx = 2;
		constraints.gridy = 6;
		constraints.gridwidth = 6;
		constraints.gridheight = 3;
		introductionArea.setLineWrap(true);
		this.add(new JScrollPane(introductionArea), constraints);
		constraints.gridheight = 1;
		constraints.gridwidth = 1;

		// monCheckBox
		constraints.gridx = 1;
		constraints.gridy = 3;
		gbl.setConstraints(monCheckBox, constraints);
		this.add(monCheckBox);
		// tueCheckBox
		constraints.gridx = 2;
		gbl.setConstraints(tueCheckBox, constraints);
		this.add(tueCheckBox);
		// wedCheckBox
		constraints.gridx = 3;
		gbl.setConstraints(wedCheckBox, constraints);
		this.add(wedCheckBox);
		// thuCheckBox
		constraints.gridx = 4;
		gbl.setConstraints(thuCheckBox, constraints);
		this.add(thuCheckBox);
		// friCheckBox
		constraints.gridx = 5;
		gbl.setConstraints(friCheckBox, constraints);
		this.add(friCheckBox);
		// satCheckBox
		constraints.gridx = 6;
		gbl.setConstraints(satCheckBox, constraints);
		this.add(satCheckBox);
		// sunCheckBox
		constraints.gridx = 7;
		gbl.setConstraints(sunCheckBox, constraints);
		this.add(sunCheckBox);
		// soundCheckBox
		constraints.gridx = 1;
		constraints.gridy = 4;
		constraints.gridwidth = 2;
		gbl.setConstraints(soundCheckBox, constraints);
		this.add(soundCheckBox);
		// windowCheckBox
		constraints.gridx = 1;
		constraints.gridy = 5;
		gbl.setConstraints(windowCheckBox, constraints);
		this.add(windowCheckBox);
		constraints.gridwidth = 1;

		// browseButton
		constraints.gridx = 7;
		constraints.gridy = 4;
		gbl.setConstraints(browseButton, constraints);
		this.add(browseButton);
		// Buttons
		constraints.gridx = 4;
		constraints.gridy = 9;
		constraints.gridwidth = 4;
		constraints.anchor = GridBagConstraints.SOUTHEAST;
		JPanel panel = new JPanel();
		panel.add(removeButton);
		panel.add(modifyButton);
		panel.add(addButton);
		gbl.setConstraints(panel, constraints);
		this.add(panel);
		constraints.gridwidth = 1;

		// eventTable
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.gridheight = 9;
		constraints.fill = GridBagConstraints.BOTH;
		eventTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		eventTable.setPreferredScrollableViewportSize(new Dimension(300, 150));
		this.add(new JScrollPane(eventTable), constraints);

		// add listener
		this.addButton.addActionListener(eventController);
		this.removeButton.addActionListener(eventController);
		this.modifyButton.addActionListener(eventController);
		this.browseButton.addActionListener(eventController);
		this.eventTable.getSelectionModel().addListSelectionListener(
				eventController);
	}

	public JButton getAddButton() {
		return addButton;
	}

	public JButton getBrowseButton() {
		return browseButton;
	}

	public EventController getEventController() {
		return eventController;
	}

	public JLabel getEventLabel() {
		return eventLabel;
	}

	public JTextField getEventNameField() {
		return eventNameField;
	}

	public JLabel getEventNameLabel() {
		return eventNameLabel;
	}

	public JTable getEventTable() {
		return eventTable;
	}

	public EventTableModel getEventTableModel() {
		return eventTableModel;
	}

	public JTextField getFileField() {
		return fileField;
	}

	public JCheckBox getFriCheckBox() {
		return friCheckBox;
	}

	public JComboBox getHourComboBox() {
		return hourComboBox;
	}

	public JTextArea getIntroductionArea() {
		return introductionArea;
	}

	public JComboBox getMinuteComboBox() {
		return minuteComboBox;
	}

	public JButton getModifyButton() {
		return modifyButton;
	}

	public JCheckBox getMonCheckBox() {
		return monCheckBox;
	}

	public JLabel getRecyleLabel() {
		return recyleLabel;
	}

	public JButton getRemoveButton() {
		return removeButton;
	}

	public JCheckBox getSatCheckBox() {
		return satCheckBox;
	}

	public JCheckBox getSoundCheckBox() {
		return soundCheckBox;
	}

	public JCheckBox getSunCheckBox() {
		return sunCheckBox;
	}

	public TaskFrame getTaskFrame() {
		return taskFrame;
	}

	public JCheckBox getThuCheckBox() {
		return thuCheckBox;
	}

	public JLabel getTimeLabel() {
		return timeLabel;
	}

	public JCheckBox getTueCheckBox() {
		return tueCheckBox;
	}

	public JCheckBox getWedCheckBox() {
		return wedCheckBox;
	}

	public JCheckBox getWindowCheckBox() {
		return windowCheckBox;
	}

	public void init() {
		this.removeButton.setEnabled(false);
		this.modifyButton.setEnabled(false);
	}

	public void setAddButton(JButton addButton) {
		this.addButton = addButton;
	}

	public void setBrowseButton(JButton browseButton) {
		this.browseButton = browseButton;
	}

	public void setEventController(EventController eventController) {
		this.eventController = eventController;
	}

	public void setEventLabel(JLabel eventLabel) {
		this.eventLabel = eventLabel;
	}

	public void setEventNameField(JTextField eventNameField) {
		this.eventNameField = eventNameField;
	}

	public void setEventNameLabel(JLabel eventNameLabel) {
		this.eventNameLabel = eventNameLabel;
	}

	public void setEventTable(JTable eventTable) {
		this.eventTable = eventTable;
	}

	public void setEventTableModel(EventTableModel eventTableModel) {
		this.eventTableModel = eventTableModel;
	}

	public void setFileField(JTextField fileField) {
		this.fileField = fileField;
	}

	public void setFriCheckBox(JCheckBox friCheckBox) {
		this.friCheckBox = friCheckBox;
	}

	public void setHourComboBox(JComboBox hourComboBox) {
		this.hourComboBox = hourComboBox;
	}

	public void setIntroductionArea(JTextArea introductionArea) {
		this.introductionArea = introductionArea;
	}

	public void setMinuteComboBox(JComboBox minuteComboBox) {
		this.minuteComboBox = minuteComboBox;
	}

	public void setModifyButton(JButton modifyButton) {
		this.modifyButton = modifyButton;
	}

	public void setMonCheckBox(JCheckBox monCheckBox) {
		this.monCheckBox = monCheckBox;
	}

	public void setRecyleLabel(JLabel recyleLabel) {
		this.recyleLabel = recyleLabel;
	}

	public void setRemoveButton(JButton removeButton) {
		this.removeButton = removeButton;
	}

	public void setSatCheckBox(JCheckBox satCheckBox) {
		this.satCheckBox = satCheckBox;
	}

	public void setSoundCheckBox(JCheckBox soundCheckBox) {
		this.soundCheckBox = soundCheckBox;
	}

	public void setSunCheckBox(JCheckBox sunCheckBox) {
		this.sunCheckBox = sunCheckBox;
	}

	public void setTaskFrame(TaskFrame taskFrame) {
		this.taskFrame = taskFrame;
	}

	public void setThuCheckBox(JCheckBox thuCheckBox) {
		this.thuCheckBox = thuCheckBox;
	}

	public void setTimeLabel(JLabel timeLabel) {
		this.timeLabel = timeLabel;
	}

	public void setTueCheckBox(JCheckBox tueCheckBox) {
		this.tueCheckBox = tueCheckBox;
	}

	public void setWedCheckBox(JCheckBox wedCheckBox) {
		this.wedCheckBox = wedCheckBox;
	}

	public void setWindowCheckBox(JCheckBox windowCheckBox) {
		this.windowCheckBox = windowCheckBox;
	}
}
